from pod.std import *

class StringPrintf(Macro):
    """
    usage:
    #set(x=4)
    #set(y=3.1459)
    #set(z="test")
    #sprintf("the values are: %d, %f, %s", $x, $y, $z)
    """
    name = "sprintf"
    doctype = "html"
    
    def __init__(self, env, scope, format, *args):
        super(StringPrintf, self).__init__()
        self.format = format
        self.vars = args
    
    def __call__(self, content):
        return self.format % self.vars
        
class Join(Macro):
    """
    usage:
    #join("a", 1, 3.45, delim=", ")
    """
    name = "join"
    doctype = "html"
    
    def __init__(self, env, scope, *args, **kwargs):
        super(Join, self).__init__()
        self.delim = kwargs.get("delim", "")
        self.values = args
        
    def __call__(self, content):
        return self.delim.join([str(e) for e in self.values])